// ==UserScript==
// @name          zolCellphoneExtractor
// @namespace     http://honguozi.meibu.com/greasemonkey/zol_cellphone_extractor
// @description	  Extract cellphone data from zol website
// @author        Conan Chan
// @homepage      http://honguozi.meibu.com/greasemonkey/zol_cellphone_extractor
// @include       http://*.zol.com.cn/*
// ==/UserScript==


// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

// Check if jQuery's loaded
function GM_wait() {
	if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
	else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();

// All your GM code must be inside this function
function letsJQuery() {
	//alert("letsJQuery "+$); // check if the dollar (jquery) function works

	//process zol cellphone list page
	//http://detail.zol.com.cn/cell_phone_index/subcate57_297_list_1.html
	$(".search_border").replaceWith("<div class='search_border'><TEXTAREA id='collecter' cols='60' rows='5'></TEXTAREA><INPUT type='button' name='collect' value='collect'/></div>");
	$(".price_content").each(function(){
		smallImage=$(this).find("div  div div  a  img").attr("src");
		productName=$(this).find("div  div div  a  img").attr("alt");
		priceBrief= $(this).find("div[class='price_brief']").text();
		$("#collecter").text($("#collecter").text()+"<Content contentId=\""+productName+"\" smallImage=\""+smallImage+"\" name=\""+productName+"\" fullName=\""+productName+"\" ><shortDesc><![CDATA["+priceBrief+"]]></shortDesc></Content>");
	});
	
	//process zol cellphone detail page
	//http://detail.zol.com.cn/cell_phone/index105686.shtml
	$(".top_ad").empty();
	$(".picture_top").each(function(){
		contentId=$(this).find("div div a img").attr("title");
		picture_big = $(this).find("div div a img").attr("src");
		category=$(this).find("div div").find(":eq(3)").text();
		$("#collecter").text($("#collecter").text()+"<Content contentId=\""+contentId+"\" largeImage=\""+picture_big+"\" categoryId=\""+category+"\"/>");		
	});
}